// pages/notify/notify-set/fault-nodify/fault-nodify.js

var app = getApp()
Page({

	/**
	* 页面的初始数据
	*/
	data: {
		switch1Checked: true,
		switch2Checked: false,
		switch3Checked:false,
		start: '00:00',
		end:'00:00',
		noticeTypeId:''
	}, 
	

	/**
	* 生命周期函数--监听页面加载
	*/
	onLoad: function (options) {
		let that = this;	
		wx.setNavigationBarTitle({
		   title: options.noticeTypeName+'设置'
		})
		
		that.setData({			
			noticeTypeId:options.noticeTypeId
		})
		that.getnNoticeSetting();
	},
	//小程序故障通知设置
    switch1Change:function(e){
		let that = this;		
		that.setNoticeM(e.detail.value,false)
	},
	//公众号故障通知设置
	switch2Change:function(e){
		let that = this;	
		that.setNoticeM(true,e.detail.value)
	},
	//获取设置
	getnNoticeSetting:function(){
		let that = this;		
		wx.request({
			url:app.globalData.baseUrl+'msg_notice/settings/'+that.data.noticeTypeId,
			method:'get',
			header: {
			  'AUTHORIZATION': app.globalData.token
			},			
			success: (res) => {
				if(res.data.code==200){
					that.setData({
						switch1Checked:res.data.data.weChatApplet,
						switch2Checked:res.data.data.weChatOfficialAccounts
					})
				}
			},
		})
		
	},
	//设置
	setNoticeM:function(weChatApplet,weChatOfficialAccounts){
		let that = this;
		wx.request({
			url:app.globalData.baseUrl+'msg_notice/settings/'+that.data.noticeTypeId+'/update',
			method:'post',
			header: {
			  'AUTHORIZATION': app.globalData.token,
			  "Content-Type": "application/x-www-form-urlencoded"
			},				
			data:{					
				weChatApplet:weChatApplet,
				weChatOfficialAccounts:weChatOfficialAccounts
			},
			success: (res) => {
				if(res.data.code==200){
					that.getnNoticeSetting();
				}
			}
		})
	
	},
	//免扰故障通知设置
	switch3Change:function(e){
		let that = this;	
		that.setData({
			switch3Checked:e.detail.value
		})
	},
	bindSTimeChange: function(e) {
		// console.log('picker发送选择改变，携带值为', e.detail.value)
		this.setData({
		  start: e.detail.value
		})
	},
	bindETimeChange: function(e) {
		// console.log('picker发送选择改变，携带值为', e.detail.value)
		this.setData({
		  end: e.detail.value
		})
	},

	/**
	* 生命周期函数--监听页面初次渲染完成
	*/
	onReady: function () {

	},

	/**
	* 生命周期函数--监听页面显示
	*/
	onShow: function () {

	},

	/**
	* 生命周期函数--监听页面隐藏
	*/
	onHide: function () {

	},

	/**
	* 生命周期函数--监听页面卸载
	*/
	onUnload: function () {

	},

	/**
	* 页面相关事件处理函数--监听用户下拉动作
	*/
	onPullDownRefresh: function () {

	},

	/**
	* 页面上拉触底事件的处理函数
	*/
	onReachBottom: function () {

	},

	/**
	* 用户点击右上角分享
	*/
	onShareAppMessage: function () {

	}
})